﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using YiLe.BLL.Service;
using YiLe.Model.Domain;

namespace YiLe.View.Permissions
{
    public partial class PermissionListForm : Form
    {
        private IPermissionService permissionService;
        
        public PermissionListForm(Spring.Context.IApplicationContext ctx)
        {
            InitializeComponent();
            permissionService = ctx["PermissionService"] as IPermissionService;
        }

        private void add_Click(object sender, EventArgs e)
        {

        }

        private void modify_Click(object sender, EventArgs e)
        {

        }

        private void delete_Click(object sender, EventArgs e)
        {

        }

        private void close_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// Form的读取事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void PermissionListForm_Load(object sender, EventArgs e)
        {
            IList<Permission> permissionList = permissionService.GetAll();
            this.bsList.DataSource = permissionList;
        }

        /// <summary>
        /// 查询权限
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (ValidateForm())
            {
                string permissionname = this.tbPermissionName.Text.Trim();
                var permission = new YiLe.Model.Domain.Permission() { PermissionName = permissionname };
                IList<YiLe.Model.Domain.Permission> permissionList = permissionService.Search(permission);
                this.bsList.DataSource = permissionList;
            }

        }

        private bool ValidateForm()
        {
            return true;
        }

    }
}
